/**
 * Created by zhaojm on 15/3/28.
 */
game.FlareEffect = cc.Class.extend({

    _sprite:null,

    ctor:function(){

        var winSize = cc.winSize;
        this._sprite = new cc.Sprite(res.flare_jpg);
        this._sprite.setBlendFunc(gl.SRC_ALPHA, gl.ONE);   // 颜色混合
        this._sprite.setOpacity(0);
        this._sprite.setRotation(-120);
        this._sprite.setScale(0.2);

    },

    _runAction : function(callbackFunc){
        var opacityAnim = cc.FadeTo.create(0.5, 255);
        var opacDim = cc.FadeTo.create(1, 0);

        var bigAnim = cc.ScaleBy.create(0.7, 1.2, 1.2);

        var biggerEase = cc.EaseSineOut.create(bigAnim);
        var moveAnim = cc.MoveBy.create(0.5, cc.p(328, 0));
        var moveEase = cc.EaseSineOut.create(moveAnim);


        var roteAnim = cc.RotateBy.create(2.5, 90);

        var rotateEase = cc.EaseExponentialOut.create(roteAnim);

        var bigger = cc.ScaleTo.create(0.5, 1);

        var removeFunc =  cc.CallFunc.create(this.removeFromLayer);

        var callbackFunc_action = cc.CallFunc.create(callbackFunc);

        this._sprite.runAction(cc.Sequence.create(opacityAnim, biggerEase, opacDim, removeFunc, callbackFunc_action));
        this._sprite.runAction(moveEase);
        this._sprite.runAction(rotateEase);
        this._sprite.runAction(bigger);
    },

    removeFromLayer : function(pSender){
        pSender.removeFromParent();
    },

    addToLayer : function(layer, callbackFunc){
        layer.addChild(this._sprite, 10);

        this._sprite.setPosition(cc.p(-30, cc.winSize.height - 130));

        this._runAction(callbackFunc);
    },


});